HEX
CREATE BUFFER 200 ALLOT
20 CONSTANT R_DATA
21 CONSTANT R_SECTCNT
22 CONSTANT R_FEATURES
23 CONSTANT R_LBA_LL
24 CONSTANT R_LBA_LH
25 CONSTANT R_LBA_HH
26 CONSTANT R_LBA_HL
27 CONSTANT R_CMD
22 CONSTANT R_ERRORS
27 CONSTANT R_STATUS
35 CONSTANT R_DEVCTL
35 CONSTANT R_ALTSTATUS
37 CONSTANT R_DRIVEADD
1C CONSTANT R_DATLO
1E CONSTANT R_DATHI
4000 CONSTANT LOADERBASE
CREATE COPIER 
00 C, 
21 C, 00 C, 41 C,
11 C, 00 C, 01 C,
01 C, 00 C, 3F C,
ED C, B0 C,
DB C, 19 C,
E6 C, 04 C,
CA C, 0B C, 40 C,
3E C, 31 C,
D3 C, 18 C,
C3 C, 00 C, 01 C,
HERE COPIER - 1- COPIER C!
: IDEIN 4F 1D PC! 4F 1F PC! ;
: IDEOUT 0F 1D PC! 0F 1F PC! ;
: CMD IDEOUT R_DATLO PC! 0 R_CMD PC! IDEIN ;
: READSTATUS R_STATUS PC@ DROP R_DATLO PC@ ;
: WAITREADY BEGIN READSTATUS 80 AND 0= UNTIL ;
: WAITDRQ BEGIN READSTATUS 08 AND UNTIL ;
: BUFFERREAD WAITDRQ 100 0 DO R_DATA PC@ DROP R_DATLO PC@ BUFFER I 2* + C! R_DATHI PC@ BUFFER I 2* + 1+ C! LOOP ;
: WREG IDEOUT SWAP FF AND R_DATLO PC! 0 SWAP PC! IDEIN ;
: RREG PC@ DROP R_DATLO PC@ ; 
: RESET 04 R_DEVCTL WREG 00 R_DEVCTL WREG ;
: SETSECTCNT R_SECTCNT WREG ;
: SETLBA 1 SETSECTCNT DUP R_LBA_LL WREG >< R_LBA_LH WREG DUP R_LBA_HL WREG >< 0F AND E0 OR R_LBA_HH WREG ;   
: SREAD WAITREADY SETLBA 20 CMD BUFFERREAD ; 
: STATUS ." S=" R_STATUS RREG . ." E=" R_ERRORS RREG . ;
: READBOOT 20 0 DO 0 I SREAD BUFFER LOADERBASE 100 + I 200 * + 200 CMOVE LOOP ;
: WRITECOPIER LOADERBASE 100 0 FILL COPIER 1+ LOADERBASE COPIER C@ CMOVE ;
: JUMPLOADER C3 5 C! LOADERBASE 6 ! 0 0 BDOS ;
: BOOT R_STATUS 80 AND IF ." BUSY!" ELSE READBOOT WRITECOPIER JUMPLOADER THEN ;
